package com.lanyam.travel.base.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanyam.travel.base.dao.DistrRecordMapper;
import com.lanyam.travel.base.dao.DistrUserMapper;
import com.lanyam.travel.base.dao.UserMapper;
import com.lanyam.travel.base.dao.statistics.ExcelMapper;
import com.lanyam.travel.base.entity.DistrRecord;
import com.lanyam.travel.base.entity.OrderGoodsDate;
import com.lanyam.travel.base.entity.User;
import com.lanyam.travel.base.entity.excelEntity.*;
import com.lanyam.travel.base.entity.vo.DistrRecordVo;
import com.lanyam.travel.base.entity.vo.OrderGoodsDateVo;
import com.lanyam.travel.base.entity.vo.TravelOrderVo;
import com.lanyam.travel.base.service.IDistrRecordService;
import com.lanyam.travel.base.service.IExcelService;
import com.lanyam.travel.base.service.UserService;
import com.lanyam.travel.base.utils.JSONResult;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 版权所有： 稻草人
 * 创建者： wenhe
 * 创建时间: 2020-02-23
 * 描述：
 * 其它：
 **/
@Service
@Transactional
public class ExcelServiceImpl implements IExcelService {

    @Autowired
    private ExcelMapper excelMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private IDistrRecordService distrRecordService;
    @Autowired
    private DistrUserMapper distrUserMapper;
    @Autowired
    private DistrRecordMapper distrRecordMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public void exportHotelGoods(HttpServletResponse response, Map map) throws Exception {
        Map loginMap = getLoginUserMap();
        map.putAll(loginMap);
        List<HotelGoods> hotelGoodsList = excelMapper.getHotelGoodsList(map);
        exportHotelGoods(response, hotelGoodsList);
    }

    @Override
    public void exportTicketGoods(HttpServletResponse response, Map map) throws Exception {
        Map loginMap = getLoginUserMap();
        map.putAll(loginMap);
        List<TicketGoods> ticketGoodsList = excelMapper.getTicketGoodsList(map);
        exportTicketGoods(response, ticketGoodsList);
    }

    @Override
    public void exportLineGoods(HttpServletResponse response, Map map) throws Exception {
        Map loginMap = getLoginUserMap();
        map.putAll(loginMap);
        List<LineGoods> lineGoodsList = excelMapper.getLineGoodsList(map);
        exportLineGoods(response, lineGoodsList);
    }

    @Override
    public IPage<TravelOrderDetailsForExcel> getExcelPage(Map queryMap, Integer page, Integer size) {
        Page<TravelOrderDetailsForExcel> pageSize = new Page<TravelOrderDetailsForExcel>(page, size);
        Map loginUserMap = getLoginUserMap();
        queryMap.putAll(loginUserMap);
        IPage<TravelOrderDetailsForExcel> excelPage = excelMapper.getExcelPage(pageSize, queryMap);
        return excelPage;
    }

    private void exportHotelGoods(HttpServletResponse response, List<HotelGoods> list) throws Exception {
        // # 设置下载项
        ServletOutputStream out = response.getOutputStream();
        String fileName = "酒店商品日统计.xls";
        fileName = new String(fileName.getBytes(), "ISO-8859-1");
        response.reset();
        response.setContentType("bin");
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

        // ## 创建excel文件
        HSSFWorkbook workbook = new HSSFWorkbook();
        String[] titles = {
                "酒店名称"
                ,"房型"
                ,"下单日期"
                ,"预约日期"
                ,"入住日期"
                ,"退房日期"
                ,"晚数"
                ,"间数"
                ,"单价"
                ,"收款金额"
                ,"供应商"
                ,"付款金额"
                ,"业务员"
                ,"业务员电话"
                ,"业务员提成"
                ,"一级分销商"
                ,"一级分销电话"
                ,"一级分销提成"
                ,"二级分销商"
                ,"二级分销电话"
                ,"二级分销提成"
                ,"三级分销商"
                ,"三级分销电话"
                ,"三级分销提成"
                ,"利润"
                ,"姓名"
                ,"联系电话"
                ,"验证码"
                ,"订单状态"
                ,"备注"
        };
        // ###创建工作簿
        HSSFSheet hssfSheet = workbook.createSheet("订单信息");
        // ### 创建表头
        HSSFRow row = hssfSheet.createRow(0);
        // #### 创建表头样式
        HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
        // #### 填写表头
        HSSFCell hssfCell = null;
        for (int i = 0; i < titles.length; i++) {
            hssfCell = row.createCell(i);//列索引从0开始
            hssfCell.setCellValue(titles[i]);//列名1
            hssfCell.setCellStyle(hssfCellStyle);//列居中显示
        }
        // ### 填写数据
        // 生成查询条件
        for (int i=0; i<list.size(); i++) {
            HotelGoods hotelGoods = list.get(i);
            HSSFRow dataRow = hssfSheet.createRow(i + 1);
            hotelGoods = handleHotelGoods(hotelGoods);
            String name = hotelGoods.getName();
            String goodsName = hotelGoods.getGoodsName();
            Date orderTime = hotelGoods.getOrderTime();
            Date bookUseDate = hotelGoods.getBookUseDate();
            Date tripTime = hotelGoods.getTripTime();
            Date bookEndDate = hotelGoods.getBookEndDate();
            Integer days = hotelGoods.getDays();
            Integer num = hotelGoods.getNum();
            BigDecimal price = hotelGoods.getPrice();
            BigDecimal totalPrice = hotelGoods.getTotalPrice();
            String supplyName = hotelGoods.getSupplyName();
            String payAmount = "";
            String zeroDistrName = hotelGoods.getZeroDistrName();
            String zeroDistrPhone = hotelGoods.getZeroDistrPhone();
            BigDecimal zeroDistrAmount = hotelGoods.getZeroDistrAmount();
            String firstDistrName = hotelGoods.getFirstDistrName();
            String firstDistrPhone = hotelGoods.getFirstDistrPhone();
            BigDecimal firstDistrAmount = hotelGoods.getFirstDistrAmount();
            String secondDistrName = hotelGoods.getSecondDistrName();
            String secondDistrPhone = hotelGoods.getSecondDistrPhone();
            BigDecimal secondDistrAmount = hotelGoods.getSecondDistrAmount();
            String thirdDistrName = hotelGoods.getThirdDistrName();
            String thirdDistrPhone = hotelGoods.getThirdDistrPhone();
            BigDecimal thirdDistrAmount = hotelGoods.getThirdDistrAmount();
            BigDecimal profit = hotelGoods.getProfit();
            String contact = hotelGoods.getContact();
            String telephone = hotelGoods.getTelephone();
            String randomCode = hotelGoods.getRandomCode();
            Integer tripStatus = hotelGoods.getTripStatus();
            String tripStatusStr = tripStatus==null?"未出行":tripStatus==0?"未出行":"已出行";
            String remarks = "";
            HSSFCell cell0 = dataRow.createCell(0);
            HSSFCell cell1 = dataRow.createCell(1);
            HSSFCell cell2 = dataRow.createCell(2);
            HSSFCell cell3 = dataRow.createCell(3);
            HSSFCell cell4 = dataRow.createCell(4);
            HSSFCell cell5 = dataRow.createCell(5);
            HSSFCell cell6 = dataRow.createCell(6);
            HSSFCell cell7 = dataRow.createCell(7);
            HSSFCell cell8 = dataRow.createCell(8);
            HSSFCell cell9 = dataRow.createCell(9);
            HSSFCell cell10 = dataRow.createCell(10);
            HSSFCell cell11 = dataRow.createCell(11);
            HSSFCell cell12 = dataRow.createCell(12);
            HSSFCell cell13 = dataRow.createCell(13);
            HSSFCell cell14 = dataRow.createCell(14);
            HSSFCell cell15 = dataRow.createCell(15);
            HSSFCell cell16 = dataRow.createCell(16);
            HSSFCell cell17 = dataRow.createCell(17);
            HSSFCell cell18 = dataRow.createCell(18);
            HSSFCell cell19 = dataRow.createCell(19);
            HSSFCell cell20 = dataRow.createCell(20);
            HSSFCell cell21 = dataRow.createCell(21);
            HSSFCell cell22 = dataRow.createCell(22);
            HSSFCell cell23 = dataRow.createCell(23);
            HSSFCell cell24 = dataRow.createCell(24);
            HSSFCell cell25 = dataRow.createCell(25);
            HSSFCell cell26 = dataRow.createCell(26);
            HSSFCell cell27 = dataRow.createCell(27);
            HSSFCell cell28 = dataRow.createCell(28);
            HSSFCell cell29 = dataRow.createCell(29);
            cell0.setCellValue(transStringFromObj(name));
            cell1.setCellValue(transStringFromObj(goodsName));
            cell2.setCellValue(transDateToStr(orderTime));
            cell3.setCellValue(transDateToStr(bookUseDate));
            cell4.setCellValue(transDateToStr(tripTime));
            cell5.setCellValue(transDateToStr(bookEndDate));
            cell6.setCellValue(transStringFromObj(days));
            cell7.setCellValue(transStringFromObj(num));
            cell8.setCellValue(transStringFromObj(price));
            cell9.setCellValue(transStringFromObj(totalPrice));
            cell10.setCellValue(transStringFromObj(supplyName));
            cell11.setCellValue(transStringFromObj(payAmount));
            cell12.setCellValue(transStringFromObj(zeroDistrName));
            cell13.setCellValue(transStringFromObj(zeroDistrPhone));
            cell14.setCellValue(transStringFromObj(zeroDistrAmount));
            cell15.setCellValue(transStringFromObj(firstDistrName));
            cell16.setCellValue(transStringFromObj(firstDistrPhone));
            cell17.setCellValue(transStringFromObj(firstDistrAmount));
            cell18.setCellValue(transStringFromObj(secondDistrName));
            cell19.setCellValue(transStringFromObj(secondDistrPhone));
            cell20.setCellValue(transStringFromObj(secondDistrAmount));
            cell21.setCellValue(transStringFromObj(thirdDistrName));
            cell22.setCellValue(transStringFromObj(thirdDistrPhone));
            cell23.setCellValue(transStringFromObj(thirdDistrAmount));
            cell24.setCellValue(transStringFromObj(profit));
            cell25.setCellValue(transStringFromObj(contact));
            cell26.setCellValue(transStringFromObj(telephone));
            cell27.setCellValue(transStringFromObj(randomCode));
            cell28.setCellValue(transStringFromObj(tripStatusStr));
            cell29.setCellValue(transStringFromObj(remarks));
        }
        // 拓宽宽度
        HSSFRow dataRowLast = hssfSheet.createRow(list.size() + 2);
        dataRowLast.createCell(0).setCellValue("--------------------------");
        dataRowLast.createCell(1).setCellValue("--------------------------");
        dataRowLast.createCell(2).setCellValue("--------------------------");
        dataRowLast.createCell(3).setCellValue("--------------------------");
        dataRowLast.createCell(4).setCellValue("--------------------------");
        dataRowLast.createCell(5).setCellValue("--------------------------");
        dataRowLast.createCell(6).setCellValue("--------------------------");
        dataRowLast.createCell(7).setCellValue("--------------------------");
        dataRowLast.createCell(8).setCellValue("--------------------------");
        dataRowLast.createCell(9).setCellValue("--------------------------");
        dataRowLast.createCell(10).setCellValue("--------------------------");
        dataRowLast.createCell(11).setCellValue("--------------------------");
        dataRowLast.createCell(12).setCellValue("--------------------------");
        dataRowLast.createCell(13).setCellValue("--------------------------");
        dataRowLast.createCell(14).setCellValue("--------------------------");
        dataRowLast.createCell(15).setCellValue("--------------------------");
        dataRowLast.createCell(16).setCellValue("--------------------------");
        dataRowLast.createCell(17).setCellValue("--------------------------");
        dataRowLast.createCell(18).setCellValue("--------------------------");
        dataRowLast.createCell(19).setCellValue("--------------------------");
        dataRowLast.createCell(20).setCellValue("--------------------------");
        dataRowLast.createCell(21).setCellValue("--------------------------");
        dataRowLast.createCell(22).setCellValue("--------------------------");
        dataRowLast.createCell(23).setCellValue("--------------------------");
        dataRowLast.createCell(24).setCellValue("--------------------------");
        dataRowLast.createCell(25).setCellValue("--------------------------");
        dataRowLast.createCell(26).setCellValue("--------------------------");
        dataRowLast.createCell(27).setCellValue("--------------------------");
        dataRowLast.createCell(28).setCellValue("--------------------------");
        dataRowLast.createCell(29).setCellValue("--------------------------");
        // 设置自适应
        for (int i=0; i<titles.length; i++) {
            hssfSheet.autoSizeColumn(i);
        }
        // excel文件写入到响应
        workbook.write(out);
    }

    private void exportTicketGoods(HttpServletResponse response, List<TicketGoods> list) throws Exception {
        // # 设置下载项
        ServletOutputStream out = response.getOutputStream();
        String fileName = "景点商品日统计.xls";
        fileName = new String(fileName.getBytes(), "ISO-8859-1");
        response.reset();
        response.setContentType("bin");
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

        // ## 创建excel文件
        HSSFWorkbook workbook = new HSSFWorkbook();
        String[] titles = {
                "景区名称"
                ,"商品名称"
                ,"下单日期"
                ,"预约日期"
                ,"大人票数"
                ,"小孩票数"
                ,"大人单价"
                ,"小孩单价"
                ,"收款金额"
                ,"供应商"
                ,"付款金额"
                ,"业务员"
                ,"业务员电话"
                ,"业务员提成"
                ,"一级分销商"
                ,"一级分销电话"
                ,"一级分销提成"
                ,"二级分销商"
                ,"二级分销电话"
                ,"二级分销提成"
                ,"三级分销商"
                ,"三级分销电话"
                ,"三级分销提成"
                ,"利润"
                ,"姓名"
                ,"联系电话"
                ,"验证码"
                ,"订单状态"
                ,"备注"
        };
        // ###创建工作簿
        HSSFSheet hssfSheet = workbook.createSheet("订单信息");
        // ### 创建表头
        HSSFRow row = hssfSheet.createRow(0);
        // #### 创建表头样式
        HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
        // #### 填写表头
        HSSFCell hssfCell = null;
        for (int i = 0; i < titles.length; i++) {
            hssfCell = row.createCell(i);//列索引从0开始
            hssfCell.setCellValue(titles[i]);//列名1
            hssfCell.setCellStyle(hssfCellStyle);//列居中显示
        }
        // ### 填写数据
        // 生成查询条件
        for (int i=0; i<list.size(); i++) {
            TicketGoods ticketGoods = list.get(i);
            HSSFRow dataRow = hssfSheet.createRow(i + 1);
            ticketGoods = handleTicketGoods(ticketGoods);
            String name = ticketGoods.getName();
            String goodsName = ticketGoods.getGoodsName();
            Date orderTime = ticketGoods.getOrderTime();
            Date bookUseDate = ticketGoods.getBookUseDate();
            Integer adultNum = ticketGoods.getAdultNum();
            Integer childNum = ticketGoods.getChildNum();
            BigDecimal adultPrice = ticketGoods.getAdultPrice();
            BigDecimal childPrice = ticketGoods.getChildPrice();
            BigDecimal totalPrice = ticketGoods.getTotalPrice();
            String supplyName = ticketGoods.getSupplyName();
            BigDecimal payPrice = ticketGoods.getPayPrice();
            String zeroDistrName = ticketGoods.getZeroDistrName();
            String zeroDistrPhone = ticketGoods.getZeroDistrPhone();
            BigDecimal zeroDistrAmount = ticketGoods.getZeroDistrAmount();
            String firstDistrName = ticketGoods.getFirstDistrName();
            String firstDistrPhone = ticketGoods.getFirstDistrPhone();
            BigDecimal firstDistrAmount = ticketGoods.getFirstDistrAmount();
            String secondDistrName = ticketGoods.getSecondDistrName();
            String secondDistrPhone = ticketGoods.getSecondDistrPhone();
            BigDecimal secondDistrAmount = ticketGoods.getSecondDistrAmount();
            String thirdDistrName = ticketGoods.getThirdDistrName();
            String thirdDistrPhone = ticketGoods.getThirdDistrPhone();
            BigDecimal thirdDistrAmount = ticketGoods.getThirdDistrAmount();
            BigDecimal profit = ticketGoods.getProfit();
            String contact = ticketGoods.getContact();
            String telephone = ticketGoods.getTelephone();
            String randomCode = ticketGoods.getRandomCode();
            Integer tripStatus = ticketGoods.getTripStatus();
            String tripStatusStr = tripStatus==null?"未出行":tripStatus==0?"未出行":"已出行";
            String remarks = "";
            HSSFCell cell0 = dataRow.createCell(0);
            HSSFCell cell1 = dataRow.createCell(1);
            HSSFCell cell2 = dataRow.createCell(2);
            HSSFCell cell3 = dataRow.createCell(3);
            HSSFCell cell4 = dataRow.createCell(4);
            HSSFCell cell5 = dataRow.createCell(5);
            HSSFCell cell6 = dataRow.createCell(6);
            HSSFCell cell7 = dataRow.createCell(7);
            HSSFCell cell8 = dataRow.createCell(8);
            HSSFCell cell9 = dataRow.createCell(9);
            HSSFCell cell10 = dataRow.createCell(10);
            HSSFCell cell11 = dataRow.createCell(11);
            HSSFCell cell12 = dataRow.createCell(12);
            HSSFCell cell13 = dataRow.createCell(13);
            HSSFCell cell14 = dataRow.createCell(14);
            HSSFCell cell15 = dataRow.createCell(15);
            HSSFCell cell16 = dataRow.createCell(16);
            HSSFCell cell17 = dataRow.createCell(17);
            HSSFCell cell18 = dataRow.createCell(18);
            HSSFCell cell19 = dataRow.createCell(19);
            HSSFCell cell20 = dataRow.createCell(20);
            HSSFCell cell21 = dataRow.createCell(21);
            HSSFCell cell22 = dataRow.createCell(22);
            HSSFCell cell23 = dataRow.createCell(23);
            HSSFCell cell24 = dataRow.createCell(24);
            HSSFCell cell25 = dataRow.createCell(25);
            HSSFCell cell26 = dataRow.createCell(26);
            HSSFCell cell27 = dataRow.createCell(27);
            HSSFCell cell28 = dataRow.createCell(28);
            cell0.setCellValue(transStringFromObj(name));
            cell1.setCellValue(transStringFromObj(goodsName));
            cell2.setCellValue(transDateToStr(orderTime));
            cell3.setCellValue(transDateToStr(bookUseDate));
            cell4.setCellValue(transStringFromObj(adultNum));
            cell5.setCellValue(transStringFromObj(childNum));
            cell6.setCellValue(transStringFromObj(adultPrice));
            cell7.setCellValue(transStringFromObj(childPrice));
            cell8.setCellValue(transStringFromObj(totalPrice));
            cell9.setCellValue(transStringFromObj(supplyName));
            cell10.setCellValue(transStringFromObj(payPrice));
            cell11.setCellValue(transStringFromObj(zeroDistrName));
            cell12.setCellValue(transStringFromObj(zeroDistrPhone));
            cell13.setCellValue(transStringFromObj(zeroDistrAmount));
            cell14.setCellValue(transStringFromObj(firstDistrName));
            cell15.setCellValue(transStringFromObj(firstDistrPhone));
            cell16.setCellValue(transStringFromObj(firstDistrAmount));
            cell17.setCellValue(transStringFromObj(secondDistrName));
            cell18.setCellValue(transStringFromObj(secondDistrPhone));
            cell19.setCellValue(transStringFromObj(secondDistrAmount));
            cell20.setCellValue(transStringFromObj(thirdDistrName));
            cell21.setCellValue(transStringFromObj(thirdDistrPhone));
            cell22.setCellValue(transStringFromObj(thirdDistrAmount));
            cell23.setCellValue(transStringFromObj(profit));
            cell24.setCellValue(transStringFromObj(contact));
            cell25.setCellValue(transStringFromObj(telephone));
            cell26.setCellValue(transStringFromObj(randomCode));
            cell27.setCellValue(transStringFromObj(tripStatusStr));
            cell28.setCellValue(transStringFromObj(remarks));
        }
        // 拓宽宽度
        HSSFRow dataRowLast = hssfSheet.createRow(list.size() + 2);
        dataRowLast.createCell(0).setCellValue("--------------------------");
        dataRowLast.createCell(1).setCellValue("--------------------------");
        dataRowLast.createCell(2).setCellValue("--------------------------");
        dataRowLast.createCell(3).setCellValue("--------------------------");
        dataRowLast.createCell(4).setCellValue("--------------------------");
        dataRowLast.createCell(5).setCellValue("--------------------------");
        dataRowLast.createCell(6).setCellValue("--------------------------");
        dataRowLast.createCell(7).setCellValue("--------------------------");
        dataRowLast.createCell(8).setCellValue("--------------------------");
        dataRowLast.createCell(9).setCellValue("--------------------------");
        dataRowLast.createCell(10).setCellValue("--------------------------");
        dataRowLast.createCell(11).setCellValue("--------------------------");
        dataRowLast.createCell(12).setCellValue("--------------------------");
        dataRowLast.createCell(13).setCellValue("--------------------------");
        dataRowLast.createCell(14).setCellValue("--------------------------");
        dataRowLast.createCell(15).setCellValue("--------------------------");
        dataRowLast.createCell(16).setCellValue("--------------------------");
        dataRowLast.createCell(17).setCellValue("--------------------------");
        dataRowLast.createCell(18).setCellValue("--------------------------");
        dataRowLast.createCell(19).setCellValue("--------------------------");
        dataRowLast.createCell(20).setCellValue("--------------------------");
        dataRowLast.createCell(21).setCellValue("--------------------------");
        dataRowLast.createCell(22).setCellValue("--------------------------");
        dataRowLast.createCell(23).setCellValue("--------------------------");
        dataRowLast.createCell(24).setCellValue("--------------------------");
        dataRowLast.createCell(25).setCellValue("--------------------------");
        dataRowLast.createCell(26).setCellValue("--------------------------");
        dataRowLast.createCell(27).setCellValue("--------------------------");
        dataRowLast.createCell(28).setCellValue("--------------------------");
        // 设置自适应
        for (int i=0; i<titles.length; i++) {
            hssfSheet.autoSizeColumn(i);
        }
        // excel文件写入到响应
        workbook.write(out);
    }

    private void exportLineGoods(HttpServletResponse response, List<LineGoods> list) throws Exception {
        // # 设置下载项
        ServletOutputStream out = response.getOutputStream();
        String fileName = "线路商品日统计.xls";
        fileName = new String(fileName.getBytes(), "ISO-8859-1");
        response.reset();
        response.setContentType("bin");
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

        // ## 创建excel文件
        HSSFWorkbook workbook = new HSSFWorkbook();
        String[] titles = {
                "门店"
                ,"国内外"
                ,"出发日期"
                ,"线路"
                ,"天数"
                ,"客人"
                ,"客人电话"
                ,"供应商"
                ,"意见"
                ,"大人"
                ,"小孩"
                ,"老人"
                ,"大人收款"
                ,"小孩收款"
                ,"老人收款"
                ,"收款总额"
                ,"收款日期"
                ,"大人结算"
                ,"小孩结算"
                ,"婴儿结算"
                ,"结算总额"
                ,"业务员"
                ,"业务员电话"
                ,"业务员提成"
                ,"一级分销商"
                ,"一级分销电话"
                ,"一级分销提成"
                ,"二级分销商"
                ,"二级分销电话"
                ,"二级分销提成"
                ,"三级分销商"
                ,"三级分销电话"
                ,"三级分销提成"
                ,"利润"
                ,"是否付款"
                ,"审核人"
                ,"确认人"
                ,"收款单号"
                ,"备注"
        };
        // ###创建工作簿
        HSSFSheet hssfSheet = workbook.createSheet("订单信息");
        // ### 创建表头
        HSSFRow row = hssfSheet.createRow(0);
        // #### 创建表头样式
        HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
        // #### 填写表头
        HSSFCell hssfCell = null;
        for (int i = 0; i < titles.length; i++) {
            hssfCell = row.createCell(i);//列索引从0开始
            hssfCell.setCellValue(titles[i]);//列名1
            hssfCell.setCellStyle(hssfCellStyle);//列居中显示
        }
        // ### 填写数据
        // 生成查询条件
        for (int i=0; i<list.size(); i++) {
            LineGoods lineGoods = list.get(i);
            HSSFRow dataRow = hssfSheet.createRow(i + 1);
            lineGoods = handleLineGoods(lineGoods);
            String storeName = lineGoods.getStoreName();
            Integer region = lineGoods.getRegion();
            String regionStr = region==null?"":region==0?"国内":"国外";
            Date bookUseDate = lineGoods.getTripTime();
            String lineName = lineGoods.getStartLocation() + " - " + lineGoods.getEndLocation();
            Integer days = lineGoods.getDays();
            String contact = lineGoods.getContact();
            String telephone = lineGoods.getTelephone();
            String supplyName = lineGoods.getSupplyName();
            String suggestion = lineGoods.getSuggestion();
            Integer adultNum = lineGoods.getAdultNum();
            Integer childNum = lineGoods.getChildNum();
            Integer babyNum = lineGoods.getBabyNum();
            BigDecimal adultPrice = lineGoods.getAdultPrice();
            BigDecimal childPrice = lineGoods.getChildPrice();
            BigDecimal babyPrice = lineGoods.getBabyPrice();
            BigDecimal totalPrice = lineGoods.getTotalPrice();
            Date payDate = lineGoods.getPayDate();
            BigDecimal adultClosePrice = lineGoods.getAdultClosePrice();
            BigDecimal childClosePrice = lineGoods.getChildClosePrice();
            BigDecimal babyClosePrice = lineGoods.getBabyClosePrice();
            BigDecimal totalClosePrice = lineGoods.getTotalClosePrice();
            BigDecimal zeroDistrAmount = lineGoods.getZeroDistrAmount();
            String zeroDistrName = lineGoods.getZeroDistrName();
            String zeroDistrPhone = lineGoods.getZeroDistrPhone();
            String firstDistrName = lineGoods.getFirstDistrName();
            String firstDistrPhone = lineGoods.getFirstDistrPhone();
            BigDecimal firstDistrAmount = lineGoods.getFirstDistrAmount();
            String secondDistrName = lineGoods.getSecondDistrName();
            String secondDistrPhone = lineGoods.getSecondDistrPhone();
            BigDecimal secondDistrAmount = lineGoods.getSecondDistrAmount();
            String thirdDistrName = lineGoods.getThirdDistrName();
            String thirdDistrPhone = lineGoods.getThirdDistrPhone();
            BigDecimal thirdDistrAmount = lineGoods.getThirdDistrAmount();
            BigDecimal profit = lineGoods.getProfit();
            Integer payStatus = lineGoods.getPayStatus();
            String payStatusStr = payStatus==null?"":payStatus==0?"未支付":payStatus==1?"已支付":payStatus==2?"退款":payStatus==9?"支付过期":"";
            String auditorName = lineGoods.getAuditorName();
            String confirmName = lineGoods.getConfirmName();
            String payNo = lineGoods.getPayNo();
            String remarks = "";
            HSSFCell cell0 = dataRow.createCell(0);
            HSSFCell cell1 = dataRow.createCell(1);
            HSSFCell cell2 = dataRow.createCell(2);
            HSSFCell cell3 = dataRow.createCell(3);
            HSSFCell cell4 = dataRow.createCell(4);
            HSSFCell cell5 = dataRow.createCell(5);
            HSSFCell cell6 = dataRow.createCell(6);
            HSSFCell cell7 = dataRow.createCell(7);
            HSSFCell cell8 = dataRow.createCell(8);
            HSSFCell cell9 = dataRow.createCell(9);
            HSSFCell cell10 = dataRow.createCell(10);
            HSSFCell cell11 = dataRow.createCell(11);
            HSSFCell cell12 = dataRow.createCell(12);
            HSSFCell cell13 = dataRow.createCell(13);
            HSSFCell cell14 = dataRow.createCell(14);
            HSSFCell cell15 = dataRow.createCell(15);
            HSSFCell cell16 = dataRow.createCell(16);
            HSSFCell cell17 = dataRow.createCell(17);
            HSSFCell cell18 = dataRow.createCell(18);
            HSSFCell cell19 = dataRow.createCell(19);
            HSSFCell cell20 = dataRow.createCell(20);
            HSSFCell cell21 = dataRow.createCell(21);
            HSSFCell cell22 = dataRow.createCell(22);
            HSSFCell cell23 = dataRow.createCell(23);
            HSSFCell cell24 = dataRow.createCell(24);
            HSSFCell cell25 = dataRow.createCell(25);
            HSSFCell cell26 = dataRow.createCell(26);
            HSSFCell cell27 = dataRow.createCell(27);
            HSSFCell cell28 = dataRow.createCell(28);
            HSSFCell cell29 = dataRow.createCell(29);
            HSSFCell cell30 = dataRow.createCell(30);
            HSSFCell cell31 = dataRow.createCell(31);
            HSSFCell cell32 = dataRow.createCell(32);
            HSSFCell cell33 = dataRow.createCell(33);
            HSSFCell cell34 = dataRow.createCell(34);
            HSSFCell cell35 = dataRow.createCell(35);
            HSSFCell cell36 = dataRow.createCell(36);
            HSSFCell cell37 = dataRow.createCell(37);
            HSSFCell cell38 = dataRow.createCell(38);
            cell0.setCellValue(transStringFromObj(storeName));
            cell1.setCellValue(transStringFromObj(regionStr));
            cell2.setCellValue(transDateToStr(bookUseDate));
            cell3.setCellValue(transStringFromObj(lineName));
            cell4.setCellValue(transStringFromObj(days));
            cell5.setCellValue(transStringFromObj(contact));
            cell6.setCellValue(transStringFromObj(telephone));
            cell7.setCellValue(transStringFromObj(supplyName));
            cell8.setCellValue(transStringFromObj(suggestion));
            cell9.setCellValue(transStringFromObj(adultNum));
            cell10.setCellValue(transStringFromObj(childNum));
            cell11.setCellValue(transStringFromObj(babyNum));
            cell12.setCellValue(transStringFromObj(adultPrice));
            cell13.setCellValue(transStringFromObj(childPrice));
            cell14.setCellValue(transStringFromObj(babyPrice));
            cell15.setCellValue(transStringFromObj(totalPrice));
            cell16.setCellValue(transStringFromObj(payDate));
            cell17.setCellValue(transStringFromObj(adultClosePrice));
            cell18.setCellValue(transStringFromObj(childClosePrice));
            cell19.setCellValue(transStringFromObj(babyClosePrice));
            cell20.setCellValue(transStringFromObj(totalClosePrice));
            cell21.setCellValue(transStringFromObj(zeroDistrName));
            cell22.setCellValue(transStringFromObj(zeroDistrPhone));
            cell23.setCellValue(transStringFromObj(zeroDistrAmount));
            cell24.setCellValue(transStringFromObj(firstDistrName));
            cell25.setCellValue(transStringFromObj(firstDistrPhone));
            cell26.setCellValue(transStringFromObj(firstDistrAmount));
            cell27.setCellValue(transStringFromObj(secondDistrName));
            cell28.setCellValue(transStringFromObj(secondDistrPhone));
            cell29.setCellValue(transStringFromObj(secondDistrAmount));
            cell30.setCellValue(transStringFromObj(thirdDistrName));
            cell31.setCellValue(transStringFromObj(thirdDistrPhone));
            cell32.setCellValue(transStringFromObj(thirdDistrAmount));
            cell33.setCellValue(transStringFromObj(profit));
            cell34.setCellValue(transStringFromObj(payStatusStr));
            cell35.setCellValue(transStringFromObj(auditorName));
            cell36.setCellValue(transStringFromObj(confirmName));
            cell37.setCellValue(transStringFromObj(payNo));
            cell38.setCellValue(transStringFromObj(remarks));
        }
        // 拓宽宽度
        HSSFRow dataRowLast = hssfSheet.createRow(list.size() + 2);
        dataRowLast.createCell(0).setCellValue("--------------------------");
        dataRowLast.createCell(1).setCellValue("--------------------------");
        dataRowLast.createCell(2).setCellValue("--------------------------");
        dataRowLast.createCell(3).setCellValue("--------------------------");
        dataRowLast.createCell(4).setCellValue("--------------------------");
        dataRowLast.createCell(5).setCellValue("--------------------------");
        dataRowLast.createCell(6).setCellValue("--------------------------");
        dataRowLast.createCell(7).setCellValue("--------------------------");
        dataRowLast.createCell(8).setCellValue("--------------------------");
        dataRowLast.createCell(9).setCellValue("--------------------------");
        dataRowLast.createCell(10).setCellValue("--------------------------");
        dataRowLast.createCell(11).setCellValue("--------------------------");
        dataRowLast.createCell(12).setCellValue("--------------------------");
        dataRowLast.createCell(13).setCellValue("--------------------------");
        dataRowLast.createCell(14).setCellValue("--------------------------");
        dataRowLast.createCell(15).setCellValue("--------------------------");
        dataRowLast.createCell(16).setCellValue("--------------------------");
        dataRowLast.createCell(17).setCellValue("--------------------------");
        dataRowLast.createCell(18).setCellValue("--------------------------");
        dataRowLast.createCell(19).setCellValue("--------------------------");
        dataRowLast.createCell(20).setCellValue("--------------------------");
        dataRowLast.createCell(21).setCellValue("--------------------------");
        dataRowLast.createCell(22).setCellValue("--------------------------");
        dataRowLast.createCell(23).setCellValue("--------------------------");
        dataRowLast.createCell(24).setCellValue("--------------------------");
        dataRowLast.createCell(25).setCellValue("--------------------------");
        dataRowLast.createCell(26).setCellValue("--------------------------");
        dataRowLast.createCell(27).setCellValue("--------------------------");
        dataRowLast.createCell(28).setCellValue("--------------------------");
        dataRowLast.createCell(29).setCellValue("--------------------------");
        dataRowLast.createCell(30).setCellValue("--------------------------");
        dataRowLast.createCell(31).setCellValue("--------------------------");
        dataRowLast.createCell(32).setCellValue("--------------------------");
        dataRowLast.createCell(33).setCellValue("--------------------------");
        dataRowLast.createCell(34).setCellValue("--------------------------");
        dataRowLast.createCell(35).setCellValue("--------------------------");
        dataRowLast.createCell(36).setCellValue("--------------------------");
        dataRowLast.createCell(37).setCellValue("--------------------------");
        dataRowLast.createCell(38).setCellValue("--------------------------");
        // 设置自适应
        for (int i=0; i<titles.length; i++) {
            hssfSheet.autoSizeColumn(i);
        }
        // excel文件写入到响应
        workbook.write(out);
    }

    /**
     * 处理酒店商品
     * @param hotelGoods
     * @return
     */
    private HotelGoods handleHotelGoods(HotelGoods hotelGoods) {
        // 晚数
        List<OrderGoodsDate> orderGoodsDateList = excelMapper.getHotelList(hotelGoods.getId());
        hotelGoods.setDays((orderGoodsDateList==null||hotelGoods.getNum()==null)?0:(orderGoodsDateList.size()/hotelGoods.getNum()));
        // 支付总价
        hotelGoods.setPayPrice(hotelGoods.getTotalPrice());
        // 单价
        BigDecimal totalPrice = hotelGoods.getTotalPrice();
        Integer days = hotelGoods.getDays();
        days = days==null?1:days;
        Integer num = hotelGoods.getNum();
        num = num==null?1:num;
        int total = days * num;
        BigDecimal price = BigDecimal.ZERO;
        if (total!=0 && totalPrice != null) {
            price = totalPrice.divide(new BigDecimal(total));
        }
        hotelGoods.setPrice(price);
        // 分销提成
        String orderDetailId = hotelGoods.getId();
        String orderUserId = hotelGoods.getOrderUserId();
        DistrInfo distrInfo = getDistrInfo(orderUserId, totalPrice, orderDetailId);
        hotelGoods.setFirstDistrName(distrInfo.getFirstDistrName());
        hotelGoods.setFirstDistrPhone(distrInfo.getFistrDistrPhone());
        hotelGoods.setFirstDistrAmount(distrInfo.getFirstDistrAmount());
        hotelGoods.setSecondDistrName(distrInfo.getSecondDistrName());
        hotelGoods.setSecondDistrPhone(distrInfo.getSecondDistrPhone());
        hotelGoods.setSecondDistrAmount(distrInfo.getSecondDistrAmount());
        hotelGoods.setThirdDistrName(distrInfo.getThirdDistrName());
        hotelGoods.setThirdDistrPhone(distrInfo.getThirdDistrPhone());
        hotelGoods.setThirdDistrAmount(distrInfo.getThirdDistrAmount());
        hotelGoods.setZeroDistrName(distrInfo.getZeroDistrName());
        hotelGoods.setZeroDistrPhone(distrInfo.getZeroDistrPhone());
        hotelGoods.setZeroDistrAmount(distrInfo.getZeroDistrAmount());
        // 计算利润
        BigDecimal payPrice = hotelGoods.getPayPrice();
        if (payPrice == null)
            payPrice = BigDecimal.ZERO;
        BigDecimal cost = hotelGoods.getFirstDistrAmount().add(hotelGoods.getSecondDistrAmount().add(hotelGoods.getThirdDistrAmount()));
        BigDecimal profit = payPrice.subtract(cost);
        hotelGoods.setProfit(profit);
        return hotelGoods;
    }

    /**
     * 处理景点数据
     * @param ticketGoods
     * @return
     */
    private TicketGoods handleTicketGoods(TicketGoods ticketGoods) {
        // 大人小孩票数量及单价
        List<OrderGoodsDateVo> orderGoodsDateList = excelMapper.getTypeList(0, ticketGoods.getId());
        BigDecimal adultTotalPrice = BigDecimal.ZERO;
        BigDecimal childTotalPrice = BigDecimal.ZERO;
        Integer adultNum = 0;
        Integer childNum = 0;

        for (OrderGoodsDate orderGoodsDate: orderGoodsDateList) {
            try {
                Integer ticketType = orderGoodsDate.getTicketType();
                Integer discountType = orderGoodsDate.getDiscountType();
                BigDecimal discountRate = new BigDecimal(orderGoodsDate.getDiscountRate());
                BigDecimal goodPrice = orderGoodsDate.getGoodPrice();
                goodPrice = goodPrice==null?BigDecimal.ZERO:goodPrice;
                // 比例优惠
                /*if (discountType == 0) {
                    goodPrice = goodPrice.multiply(discountRate);
                } else if (discountType == 1) { // 金额优惠
                    goodPrice = goodPrice.subtract(discountRate);
                }*/
                Integer ticketNum = orderGoodsDate.getGoodQuality()==null?1:orderGoodsDate.getGoodQuality();
                // 儿童票
                if (ticketType == 5) {
                    childNum = childNum + ticketNum;
                    childTotalPrice = childTotalPrice.add(goodPrice.multiply(new BigDecimal(ticketNum)));
                } else if (ticketType == 2) { // 成人票
                    adultNum += ticketNum;
                    adultTotalPrice = adultTotalPrice.add(goodPrice.multiply(new BigDecimal(ticketNum)));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        BigDecimal adultPrice = BigDecimal.ZERO;
        BigDecimal childPrice = BigDecimal.ZERO;
        if (adultNum != 0) {
            adultPrice = adultTotalPrice.divide(new BigDecimal(adultNum));
        }
        if (childNum != 0) {
            childPrice = childTotalPrice.divide(new BigDecimal(childNum));
        }
        ticketGoods.setAdultNum(adultNum);
        ticketGoods.setChildNum(childNum);
        ticketGoods.setAdultPrice(adultPrice);
        ticketGoods.setChildPrice(childPrice);
        // 付款金额
        ticketGoods.setPayPrice(ticketGoods.getTotalPrice());
        // 分销
        String orderDetailId = ticketGoods.getId();
        String orderUserId = ticketGoods.getOrderUserId();
        BigDecimal totalPrice = ticketGoods.getTotalPrice();
        DistrInfo distrInfo = getDistrInfo(orderUserId, totalPrice, orderDetailId);
        ticketGoods.setFirstDistrName(distrInfo.getFirstDistrName());
        ticketGoods.setFirstDistrPhone(distrInfo.getFistrDistrPhone());
        ticketGoods.setFirstDistrAmount(distrInfo.getFirstDistrAmount());
        ticketGoods.setSecondDistrName(distrInfo.getSecondDistrName());
        ticketGoods.setSecondDistrPhone(distrInfo.getSecondDistrPhone());
        ticketGoods.setSecondDistrAmount(distrInfo.getSecondDistrAmount());
        ticketGoods.setThirdDistrName(distrInfo.getThirdDistrName());
        ticketGoods.setThirdDistrPhone(distrInfo.getThirdDistrPhone());
        ticketGoods.setThirdDistrAmount(distrInfo.getThirdDistrAmount());
        ticketGoods.setZeroDistrName(distrInfo.getZeroDistrName());
        ticketGoods.setZeroDistrPhone(distrInfo.getZeroDistrPhone());
        ticketGoods.setZeroDistrAmount(distrInfo.getZeroDistrAmount());
        // 利润
        BigDecimal profit = BigDecimal.ZERO;
        if (ticketGoods.getPayPrice() == null)
            ticketGoods.setPayPrice(BigDecimal.ZERO);
        profit = ticketGoods.getPayPrice().subtract(ticketGoods.getFirstDistrAmount()).subtract(ticketGoods.getSecondDistrAmount()).subtract(ticketGoods.getThirdDistrAmount());
        ticketGoods.setProfit(profit);
        return ticketGoods;
    }

    /**
     * 处理线路数据
     * @param lineGoods
     * @return
     */
    private LineGoods handleLineGoods(LineGoods lineGoods) {
        // 大人小孩票数量及单价
        List<OrderGoodsDateVo> orderGoodsDateList = excelMapper.getTypeList(2, lineGoods.getId());
        BigDecimal adultTotalPrice = BigDecimal.ZERO;
        BigDecimal childTotalPrice = BigDecimal.ZERO;
        BigDecimal babyTotalPrice = BigDecimal.ZERO;
        Integer adultNum = 0;
        Integer childNum = 0;
        Integer babyNum = 0;
        for (OrderGoodsDate orderGoodsDate: orderGoodsDateList) {
            try {
                Integer ticketType = orderGoodsDate.getTicketType();
                Integer discountType = orderGoodsDate.getDiscountType();
                BigDecimal discountRate = new BigDecimal(orderGoodsDate.getDiscountRate());
                BigDecimal goodPrice = orderGoodsDate.getGoodPrice();
                goodPrice = goodPrice==null?BigDecimal.ZERO:goodPrice;
                // 比例优惠
                /*if (discountType == 0) {
                    goodPrice = goodPrice.multiply(discountRate);
                } else if (discountType == 1) { // 金额优惠
                    goodPrice = goodPrice.subtract(discountRate);
                }*/
                Integer ticketNum = orderGoodsDate.getGoodQuality()==null?1:orderGoodsDate.getGoodQuality();
                // 儿童票
                if (ticketType == 5) {
                    childNum+=ticketNum;
                    childTotalPrice = childTotalPrice.add(goodPrice.multiply(new BigDecimal(ticketNum)));
                } else if (ticketType == 2) { // 成人票
                    adultNum+=ticketNum;
                    adultTotalPrice = adultTotalPrice.add(goodPrice.multiply(new BigDecimal(ticketNum)));
                } else if (ticketType == 3) { // 老人
                    babyNum+=ticketNum;
                    babyTotalPrice = babyTotalPrice.add(goodPrice.multiply(new BigDecimal(ticketNum)));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        BigDecimal adultPrice = BigDecimal.ZERO;
        BigDecimal childPrice = BigDecimal.ZERO;
        BigDecimal babyPrice = BigDecimal.ZERO;
        if (adultNum != 0) {
            adultPrice = adultTotalPrice.divide(new BigDecimal(adultNum));
        }
        if (childNum != 0) {
            childPrice = childTotalPrice.divide(new BigDecimal(childNum));
        }
        if (babyNum != 0) {
            babyPrice = babyTotalPrice.divide(new BigDecimal(babyNum));
        }
        lineGoods.setAdultNum(adultNum);
        lineGoods.setChildNum(childNum);
        lineGoods.setBabyNum(babyNum);
        lineGoods.setAdultPrice(adultPrice);
        lineGoods.setChildPrice(childPrice);
        lineGoods.setBabyPrice(babyPrice);
        // 各种类型的结算
        lineGoods.setAdultClosePrice(adultTotalPrice);
        lineGoods.setChildClosePrice(childTotalPrice);
        lineGoods.setBabyClosePrice(babyTotalPrice);
        lineGoods.setTotalClosePrice(lineGoods.getTotalPrice());
        // 分销
        String orderDetailId = lineGoods.getId();
        String orderUserId = lineGoods.getOrderUserId();
        BigDecimal totalPrice = lineGoods.getTotalPrice();
        DistrInfo distrInfo = getDistrInfo(orderUserId, totalPrice, orderDetailId);
        lineGoods.setFirstDistrName(distrInfo.getFirstDistrName());
        lineGoods.setFirstDistrPhone(distrInfo.getFistrDistrPhone());
        lineGoods.setFirstDistrAmount(distrInfo.getFirstDistrAmount());
        lineGoods.setSecondDistrName(distrInfo.getSecondDistrName());
        lineGoods.setSecondDistrPhone(distrInfo.getSecondDistrPhone());
        lineGoods.setSecondDistrAmount(distrInfo.getSecondDistrAmount());
        lineGoods.setThirdDistrName(distrInfo.getThirdDistrName());
        lineGoods.setThirdDistrPhone(distrInfo.getThirdDistrPhone());
        lineGoods.setThirdDistrAmount(distrInfo.getThirdDistrAmount());
        lineGoods.setZeroDistrName(distrInfo.getZeroDistrName());
        lineGoods.setZeroDistrPhone(distrInfo.getZeroDistrPhone());
        lineGoods.setZeroDistrAmount(distrInfo.getZeroDistrAmount());
        // 利润
        BigDecimal profit = BigDecimal.ZERO;
        if (lineGoods.getTotalPrice() == null)
            lineGoods.setTotalPrice(BigDecimal.ZERO);
        profit = lineGoods.getTotalPrice().subtract(lineGoods.getFirstDistrAmount()).subtract(lineGoods.getSecondDistrAmount()).subtract(lineGoods.getThirdDistrAmount()).subtract(lineGoods.getZeroDistrAmount());
        lineGoods.setProfit(profit);
        return lineGoods;
    }

    /**
     * 获取分销商信息
     * @return
     */
    private DistrInfo getDistrInfo(String orderUserId, BigDecimal orderMoney, String orderId) {
        DistrInfo distrInfo = new DistrInfo();
        List<DistrRecordVo> distrList = distrRecordMapper.getListByOrderDetailId(orderId);
        for (DistrRecord distrRecord: distrList) {
            String userId = distrRecord.getUserId();
            User user = userMapper.selectById(userId);
            Integer dislevel = distrRecord.getDislevel();
            if (dislevel==1) {
                distrInfo.setFirstDistrName(user.getName());
                distrInfo.setFistrDistrPhone(user.getPhone());
                distrInfo.setFirstDistrAmount(distrRecord.getAmount());
            } else if (dislevel==2) {
                distrInfo.setSecondDistrName(user.getName());
                distrInfo.setSecondDistrPhone(user.getPhone());
                distrInfo.setSecondDistrAmount(distrRecord.getAmount());
            } else if (dislevel==3) {
                distrInfo.setThirdDistrName(user.getName());
                distrInfo.setThirdDistrPhone(user.getPhone());
                distrInfo.setThirdDistrAmount(distrRecord.getAmount());
            } else if (dislevel==0) {
                distrInfo.setZeroDistrName(user.getName());
                distrInfo.setZeroDistrPhone(user.getPhone());
                distrInfo.setZeroDistrAmount(distrRecord.getAmount());
            }
        }
        // 保证分销金额初始化
        if (distrInfo.getFirstDistrAmount() == null)
            distrInfo.setFirstDistrAmount(BigDecimal.ZERO);
        if (distrInfo.getSecondDistrAmount() == null)
            distrInfo.setSecondDistrAmount(BigDecimal.ZERO);
        if (distrInfo.getThirdDistrAmount() == null)
            distrInfo.setThirdDistrAmount(BigDecimal.ZERO);
        if (distrInfo.getZeroDistrAmount() == null)
            distrInfo.setZeroDistrAmount(BigDecimal.ZERO);
        return distrInfo;
    }

    /**
     * 根据对象获取字符串
     * @param object
     * @return
     */
    private String transStringFromObj(Object object) {
        if (object == null) {
            return "";
        } else {
            return object.toString();
        }
    }

    /**
     * 将日期转换成指定格式字符串
     * @param date
     * @return
     */
    private String transDateToStr(Date date) {
        if(date == null)
            return "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateStr = simpleDateFormat.format(date);
        return dateStr;
    }

    private Map getLoginUserMap() {
        Map map = new HashMap();
        try {
            User currentUser = userService.getCurrentUser();
            if (currentUser != null) {
                if (currentUser.getRoleId() != null && currentUser.getRoleId().equals("2")) {
                    map.put("roleType", "admin");
                } else {
                    map.put("roleType", "notAdmin");
                    map.put("loginUser", currentUser.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
}
